package com.apptravel.web.controller.site;

import com.apptravel.dao.HotelDAO;
import com.apptravel.dao.Page;
import com.apptravel.dao.TicketDAO;
import com.apptravel.entity.Hotel;
import com.apptravel.entity.Ticket;
import com.apptravel.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 12-1-29
 * Time: 下午12:03
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class SiteController {

    private static final String TICKET = "/ticket";
    
    private static final String HOTEL = "/hotel";

    private static final String TICKET_VIEW = "site/ticket";
    
    private static final String HOTEL_VIEW = "site/hotel";

    @Autowired
    private TicketDAO ticketDao;

    @Autowired
    private HotelDAO hotelDao;

    /**
     * 机票页.
     * 
     * @param model
     * @return
     */
    @RequestMapping(TICKET)
    public String ticket(ModelMap model,Integer page, Integer rows){
        Map<String,Object> params = new HashMap<String,Object>();
        int pageNo = Constants.DEFAULT_PAGE;
        if (page != null && page > 0)
            pageNo = page;
        int pageSize = Constants.DEFAULT_PAGE_SIZE;
        if (rows != null && rows > 0)
            pageSize = rows;
        Page<Ticket> list = ticketDao.getList(params, pageNo, pageSize);
        model.put("page", list);
        return TICKET_VIEW;
    }

    /**
     * 酒店.
     *
     * @param model
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping(HOTEL)
    public String hotel(ModelMap model, Integer page, Integer rows) {
        Map<String, Object> params = new HashMap<String, Object>();
        int pageNo = Constants.DEFAULT_PAGE;
        if (page != null && page > 0)
            pageNo = page;
        int pageSize = Constants.DEFAULT_PAGE_SIZE;
        if (rows != null && rows > 0)
            pageSize = rows;
        Page<Hotel> list = hotelDao.getList(params, pageNo, pageSize);
        model.put("page", list);
        return HOTEL_VIEW;
    }



}
